// Load election data and merge with score data

* load data created by table2_create_elections.do
use ".dta", clear

unique surname_state_congress_first

// drop non-unique observations
sort surname_state_congress_first
g u=1 if surname_state_congress_first==surname_state_congress_first[_n-1] | surname_state_congress_first==surname_state_congress_first[_n+1]
drop if u==1

// merge with data created by table2_create_score.do
merge 1:1 surname_state_congress_first using ".dta"

keep if _merge==3

//Different samples
// 1992 last year of DemMaj
g sample1=1 if yr>=1978 & yr<=1994
label variable sample1 "1978-1994"
tab demmaj if sample1==1
g sample2=1 if yr>=1990 & yr<=2004
label variable sample2 "1990-2004"
tab demmaj if sample2==1
g sample3=1 if yr>=1982 & yr<=2004
label variable sample3 "1982-2004"
g sample4=1 if yr>=1978 & yr<=1992
label variable sample4 "Dem yrs: 1978-92"
g sample5=1 if yr>=1994 & yr<=2004
label variable sample5 "Rep yrs: 1994-2004"
g sample6=1 //all
label variable sample6 "1946-2006"
g sample7=1 if yr==1946 | yr==1952
label variable sample7 "Rep yrs: 1946 & 1952"
g sample8=1 if yr>=1954 & yr<=1976
label variable sample8 "Dem yrs: 1954-1976"
g sample9=1 if yr>=1946 & yr<=1958 
label variable sample9 "1946-1958"
g sample10=1 if yr>=1946 & yr<=1976
label variable sample10 "1946-1976"


* set main directory
cd ""

save "data/table2/table2.dta", replace


                                                                                          